#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include "header.h"
#include "File_Operations.h"
#include "hash.h"

void initialize()
{
	int i;
	char code='a';
	for(i=0;i<26;i++,code++)
	 {
	 h[i].key=code;
	 h[i].b=NULL;
	 }
	}

char hash_key(char *file_name)
	{
	char key;
	key=tolower(*file_name);
	return key;
}

void hashing(char *file_name)
{
	 char key=hash_key(file_name);
	 printf("filename: %s\n",file_name);
	 printf("hash key:%c\n",key);
	 int index=key-97;
	 TEMP=(struct bucket*)malloc(sizeof(struct bucket));
	 strcpy(TEMP->file_path,FDESC.Absolute_path);
	 TEMP->next=NULL;
	 HEAD=h[index].b;
	 if(HEAD==NULL)
	 {
	  	h[index].b=TEMP;
	 } 
	 else
	 {
		TEMP->next=HEAD;
		h[index].b=TEMP;
	 } 
}

void iterate(char key,struct bucket *b)
{
	TEMP=b;
	printf("\n%c",key);
	while(TEMP!=NULL)
	 {
	
		printf("-->%s ",TEMP->file_path);
		TEMP=TEMP->next;
	 }
}

